import { createI18n } from 'vue-i18n'
import elEnLocale from 'element-plus/es/locale/lang/en'
import elZhLocale from 'element-plus/es/locale/lang/zh-cn'
import enLocale from './lang/en'
import zhLocale from './lang/zh-cn'

const messages = {
  en: {
    ...enLocale,
    ...elEnLocale
  },
  'zh-cn': {
    ...zhLocale,
    ...elZhLocale
  }
}

export const getLocale = ():string => {
  // 不存在 获取系统语言
  const language = navigator.language.toLowerCase()
  const locales = Object.keys(messages)
  return locales.includes(language)?language:'zh-cn'
}

const i18n = createI18n({
  globalInjection: true,
  legacy: false, // you must set `false`, to use Composition API
  locale: getLocale(),
  messages: messages
})
export default i18n

export const langs = [
  { key: 'zh-cn', title: '中文简体' },
  { key: 'en', title: 'English' }
]